home *** CD-ROM | disk | FTP | other *** search
/ Supercompiler 1997 / SUPERCOMPILER97.iso / BC++ Builder / DATA.Z / EXPERTS.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-10  |  9.5 KB  |  328 lines

  1. //---------------------------------------------------------------------------
  2. // Borland C++Builder
  3. // Copyright (c) 1987, 1997 Borland International Inc.  All Rights Reserved.
  4. //---------------------------------------------------------------------------
  5. //---------------------------------------------------------------------------
  6. #include <vcl\sharemem.hpp>
  7. #include <vcl\vcl.h>
  8. #pragma hdrstop
  9. //---------------------------------------------------------------------------
  10. //   Important note about DLL memory management:
  11. //
  12. //   If your DLL exports any functions that pass String objects (or structs/
  13. //   classes containing nested Strings) as parameter or function results,
  14. //   you will need to add the library BCBMM.LIB to both the DLL project and any
  15. //   EXE projects that use the DLL.  This will change the DLL and its calling
  16. //   EXE's to use the BCBMM.DLL as their memory manager.  In these cases,
  17. //   the file BCBMM.DLL should be deployed along with your DLL.
  18. //
  19. //   To avoid using BCBMM.DLL, pass string information using "char *" or
  20. //   ShortString parameters.
  21. //---------------------------------------------------------------------------
  22. USERES("experts.res");
  23. USEFORM("filters.cpp", FilterDlg);
  24. USEFORM("dlg.cpp", DlgExpert);
  25. USEFORM("app.cpp", AppExpert);
  26. USERC("exptbmps.rc");
  27. USERC("strings.rc");
  28. USELIB("Bcbmm.lib");
  29. //---------------------------------------------------------------------------
  30. #include <ShareMem.hpp>
  31. #include <Forms.hpp>
  32. #include <Windows.hpp>
  33. #include <ExptIntf.hpp>
  34. #include <ToolIntf.hpp>
  35. #include <VirtIntf.hpp>
  36. #include <SysUtils.hpp>
  37.  
  38. #include "Exconst.h"       // external constants
  39. #include "Dlg.h"           // dialogbox expert
  40. #include "App.h"           // application expert
  41.  
  42. #pragma resource "*.RES"
  43.  
  44. String       s;             // utilty String object
  45. String       *ss;
  46. TExpertState tx;
  47. HINSTANCE    instance;
  48.  
  49. /////////////////////////////////////////// TDialogExpert ///////
  50. class __declspec(delphiclass) TDialogExpert;
  51. class TDialogExpert: public TIExpert {
  52.      typedef TIExpert inherited;
  53.   public:
  54.     String __stdcall GetName(void);
  55.     String __stdcall GetComment(void);
  56.     HICON __stdcall GetGlyph(void);
  57.     TExpertStyle __stdcall GetStyle(void);
  58.     TExpertState __stdcall GetState(void);
  59.     String __stdcall GetIDString(void);
  60.     String __stdcall GetAuthor(void);
  61.     String __stdcall GetPage(void);
  62.     String __stdcall GetMenuText(void) { return NULL; }
  63.     void __stdcall Execute(void);
  64.  
  65.     // This is required to realize the linkage; without it we
  66.     // don't get a virtual table. This has something to do with
  67.     // the implicit derivation of TIExpert from VCL's TObject.
  68.     __fastcall TDialogExpert(void) {}
  69.     __fastcall ~TDialogExpert(void) {}
  70. };
  71.  
  72. /////////////////////////////////////////// TApplicationExpert //
  73. class __declspec(delphiclass) TApplicationExpert;
  74. class TApplicationExpert: public TIExpert {
  75.      typedef TIExpert inherited;
  76.   public:
  77.     String __stdcall GetName(void);
  78.     String __stdcall GetComment(void);
  79.     HICON __stdcall GetGlyph(void);
  80.     TExpertStyle __stdcall GetStyle(void);
  81.     TExpertState __stdcall GetState(void);
  82.     String __stdcall GetIDString(void);
  83.     String __stdcall GetAuthor(void);
  84.     String __stdcall GetPage(void);
  85.     String __stdcall GetMenuText(void) { return NULL; }
  86.     void __stdcall Execute(void);
  87.  
  88.     // This is required to realize the linkage; without it we
  89.     // don't get a virtual table
  90.     __fastcall TApplicationExpert(void) {}
  91.     __fastcall ~TApplicationExpert(void) {}
  92. };
  93.  
  94. String Author("Borland");
  95. String DlgID("Borland.DlgExpertDemo");
  96. String AppID("Borland>AppExpertDemo");
  97.  
  98. //---------------------------------------------------------------
  99. void HandleException(void)
  100. {
  101.   ToolServices->RaiseException(ReleaseException());
  102. } // end of HandleException()
  103.  
  104. //========================================= TDialogExpert =======
  105. String __stdcall TDialogExpert::GetName(void)
  106. {
  107.   try
  108.   {
  109.     s = LoadStr(sDlgExpertName);
  110.   } catch(...)
  111.   {
  112.     HandleException();
  113.   }
  114.   return s;
  115. } // end of TDialogExpert::GetName()
  116.  
  117. //========================================= TDialogExpert =======
  118. String __stdcall TDialogExpert::GetComment(void)
  119. {
  120.   try
  121.   {
  122.     s = LoadStr(sDlgExpertDesc);
  123.   } catch(...)
  124.   {
  125.     HandleException();
  126.   }
  127.   return s;
  128. } // end of TDialogExpert::GetComment()
  129.  
  130. //========================================= TDialogExpert =======
  131. HICON __stdcall TDialogExpert::GetGlyph(void)
  132. {
  133.   HICON icon;
  134.   try
  135.   {
  136.     icon = LoadIcon((void*)HInstance, "DLGEXPT");
  137.   } catch(...)
  138.   {
  139.     HandleException();
  140.   }
  141.   return icon;
  142. } // end of TDialogExpert::GetGlyph()
  143.  
  144. //========================================= TDialogExpert =======
  145. TExpertStyle __stdcall TDialogExpert::GetStyle(void)
  146. {
  147.   return esForm;
  148. } // end of TDialogExpert::GetStyle()
  149.  
  150. //========================================= TDialogExpert =======
  151. TExpertState __stdcall TDialogExpert::GetState(void)
  152. {
  153.   tx << esEnabled;
  154.   return tx;
  155. } // end of TDialogExpert::GetState()
  156.  
  157. //========================================= TDialogExpert =======
  158. String __stdcall TDialogExpert::GetIDString(void)
  159. {
  160.   return DlgID;
  161. } // end of TDialogExpert::GetIDString()
  162.  
  163. //========================================= TDialogExpert =======
  164. String __stdcall TDialogExpert::GetAuthor(void)
  165. {
  166.   return Author;
  167. } // end of TDialogExpert::GetAuthor()
  168.  
  169. //========================================= TDialogExpert =======
  170. String __stdcall TDialogExpert::GetPage(void)
  171. {
  172.   try
  173.   {
  174.     s = LoadStr(sDialogsPage);
  175.   } catch(...)
  176.   {
  177.     HandleException();
  178.   }
  179.   return s;
  180. } // end of TDialogExpert::GetPage()
  181.  
  182. //========================================= TDialogExpert =======
  183. void __stdcall TDialogExpert::Execute(void)
  184. {
  185.   try
  186.   {
  187.     DialogExpert(ToolServices);
  188.   } catch(...)
  189.   {
  190.     HandleException();
  191.   }
  192. } // end of TDialogExpert::Execute()
  193.  
  194. //========================================= TApplicationExpert ==
  195. String __stdcall TApplicationExpert::GetName(void)
  196. {
  197.   try
  198.   {
  199.     s = LoadStr(sAppExpertName);
  200.   } catch(...)
  201.   {
  202.     HandleException();
  203.   }
  204.   return s;
  205. } // end of TApplicationExpert::GetName()
  206.  
  207. //========================================= TApplicationExpert ==
  208. String __stdcall TApplicationExpert::GetComment(void)
  209. {
  210.   try
  211.   {
  212.     s = LoadStr(sAppExpertDesc);
  213.   } catch(...)
  214.   {
  215.     HandleException();
  216.   }
  217.   return s;
  218. } // end of TApplicationExpert::GetComment()
  219.  
  220. //========================================= TApplicationExpert ==
  221. HICON __stdcall TApplicationExpert::GetGlyph(void)
  222. {
  223.   HICON glyph;
  224.   try
  225.   {
  226.     glyph = LoadIcon((void*)HInstance, "APPEXPT");
  227.   } catch(...)
  228.   {
  229.     HandleException();
  230.   }
  231.   return glyph;
  232. } // end of TApplicationExpert::GetGlyph()
  233.  
  234. //========================================= TApplicationExpert ==
  235. TExpertStyle __stdcall TApplicationExpert::GetStyle(void)
  236. {
  237.   return esProject;
  238. } // end of TApplicationExpert::GetStyle()
  239.  
  240. //========================================= TApplicationExpert ==
  241. TExpertState __stdcall TApplicationExpert::GetState(void)
  242. {
  243.   tx << esEnabled;
  244.   return tx;
  245. } // end of TApplicationExpert::GetState()
  246.  
  247. //========================================= TApplicationExpert ==
  248. String __stdcall TApplicationExpert::GetIDString(void)
  249. {
  250.   return AppID;
  251. } // end of TApplicationExpert::GetIDString()
  252.  
  253. //========================================= TApplicationExpert ==
  254. String __stdcall TApplicationExpert::GetAuthor(void)
  255. {
  256.   return Author;
  257. } // end of TApplicationExpert::GetAuthor()
  258.  
  259. //========================================= TApplicationExpert ==
  260. String __stdcall TApplicationExpert::GetPage(void)
  261. {
  262.   try
  263.   {
  264.     s = LoadStr(sProjectsPage);
  265.   } catch(...)
  266.   {
  267.     HandleException();
  268.   }
  269.   return s;
  270. } // end of TApplicationExpert::GetPage()
  271.  
  272. //========================================= TApplicationExpert ==
  273. void __stdcall TApplicationExpert::Execute(void)
  274. {
  275.   try
  276.   {
  277.     ApplicationExpert(ToolServices);
  278.   } catch(...)
  279.   {
  280.     HandleException();
  281.   }
  282. } // end of TApplicationExpert::Execute()
  283.  
  284. //---------------------------------------------------------------
  285. extern "C" __declspec(dllexport) void __fastcall DoneExpert(void)
  286. {
  287.   // Put any general destruction code here.  Note that the
  288.   // IDE will destroy any experts which have been registered.
  289. }
  290.  
  291. //---------------------------------------------------------------
  292. extern "C" __declspec(dllexport) bool _stdcall INITEXPERT0016(TIToolServices* ToolServices,
  293.                                                TExpertRegisterProc RegisterProc,
  294.                                                TExpertTerminateProc &Terminate)
  295. {
  296.   // make sure we"re the first and only instance
  297.   int Result = Exptintf::ToolServices == NULL;
  298.   if (!Result) return false;
  299.  
  300.   Exptintf::ToolServices = ToolServices;
  301.   if (ToolServices != NULL)
  302.     Application->Handle = ToolServices->GetParentHandle();
  303.   else
  304.     return false;
  305.  
  306.   Terminate = DoneExpert;
  307.  
  308.   // register the experts
  309.   TDialogExpert *de = new TDialogExpert;
  310.   TApplicationExpert *ae = new TApplicationExpert;
  311.   (*RegisterProc)(de);
  312.   (*RegisterProc)(ae);
  313.  
  314.   return true;
  315. } // end of InitExpert()
  316.  
  317. //***************************************************************
  318. extern "C" __declspec(dllexport) int WINAPI DllEntryPoint(HINSTANCE hinst,
  319.                                                unsigned long reason,
  320.                                                void*)
  321. {
  322.   instance = hinst;
  323.   return 1;
  324. }
  325. //---------------------------------------------------------------
  326.  
  327.  
  328.